#include <stdlib.h>
#include "queue.h"
#include "erros.h"
#include "graph.h"
#include "estruturas.h"



#define MAX_ELEM numVert

struct queue{
	int LQueue[MAX_ELEM];			//area onde se armazena
	unsigned int head;				//cabeça da fila
	unsigned int tail;				//cauda da fila
};


Queue queueCreate(){
	Queue q;
	if((q = (Queue)malloc(sizeof(struct queue))) == NULL)		//aloca memoria para a fila
		return NULL;
	q->head = MAX_ELEM;
	q->tail = 0;
	return q;
}


int queueDestroy(Queue *ptrq){
	Queue aux = *ptrq;
	if(aux == NULL) return NO_QUEUE;

	free(aux);									//liberta a memoria ocupada por toda queue
	*ptrq = NULL;								//coloca o apontador para a queue a NULL
	return OK;
}


int queueEnqueue(Queue ptrq, Node nd){
	if(ptrq == NULL) return NO_QUEUE;
	if(ptrq->head == ptrq->tail) return QUEUE_FULL;

	ptrq->LQueue[ptrq->tail] = nd;
	if(ptrq->head == MAX_ELEM) ptrq->head = ptrq->tail;
	ptrq->tail = ++ptrq->tail % MAX_ELEM;
	return OK;
}


int queueDequeue(Queue ptrq, Node *nd){
	if(ptrq == NULL) return NO_QUEUE;
	if(ptrq->head == MAX_ELEM) return QUEUE_EMPTY;
	if(nd == NULL) return NULL_PTR;

	*nd = ptrq->LQueue[ptrq->head];
	ptrq->head = ++ptrq->head % MAX_ELEM;
	if(ptrq->head == ptrq->tail) ptrq->head = MAX_ELEM;
	return OK;
}

int queueEmpty(Queue ptrq){
	if(ptrq->head == MAX_ELEM) return 1;	//se estiver vazia devolve 1
	else return 0;
	return 0;
}